<!--
 * @Descripttion:
 * @version:
 * @Author: 穆宏宇
 * @Date: 2020-09-28 20:00:38
 * @LastEditors: 穆宏宇
 * @LastEditTime: 2020-11-09 14:52:06
-->
<template>
  <div class="common-cursor">

    <div class="common-cursor-item set-flex set-column" @click="settleup">
      <div @mouseover="getShoppingcarNumFn">
        <el-badge :value="num" class="item">
            <i class="iconfont icongouwucheman"></i>
        </el-badge>
      </div>
      购物车
    </div>
    <!-- <div class="common-cursor-item set-flex set-column" @click="customerService">
      <div>
        <i class="iconfont iconkehuzhichi"></i>
      </div>
      客户支持
    </div> -->
    <div class="common-cursor-item set-flex set-column" @click="toTop">
      <div>
        <i class="iconfont iconjiantou_arrow591"></i>
      </div>
      顶 部
    </div>
  </div>
</template>
<!--
 * @Descripttion:
 * @version:
 * @Author: 穆宏宇
 * @Date: 2020-09-28 20:00:38
 * @LastEditors: 穆宏宇
 * @LastEditTime: 2020-11-09 14:52:06
-->
<template>
  <div class="common-cursor">

    <div class="common-cursor-item set-flex set-column" @click="settleup">
      <div @mouseover="getShoppingcarNumFn">
        <el-badge :value="num" class="item">
            <i class="iconfont icongouwucheman"></i>
        </el-badge>
      </div>
      购物车
    </div>
    <div class="common-cursor-item set-flex set-column" @click="customerService">
      <div>
        <i class="iconfont iconkehuzhichi"></i>
      </div>
      客户支持
    </div>
    <div class="common-cursor-item set-flex set-column" @click="toTop">
      <div>
        <i class="iconfont iconjiantou_arrow591"></i>
      </div>
      顶 部
    </div>
  </div>
</template>

<script>
import { getShoppingcarNum } from '@/api/mall.api'

export default {
  data() {
    return {
      num: ''
    }
  },
  created(){
    if (this.isLogin()) {
      this.getShoppingcarNumFn();
    }
  },
  methods: {
    // 回到顶部
    toTop() {
      this.$emit('toTop')
    },
    // 获取购物车数量
    getShoppingcarNumFn(){
      getShoppingcarNum().then(res=>{
        const numValue = Number(res)
        if (numValue <= 0) {
          this.num = ''
        } else if (numValue > 99) {
          this.num = '99+'
        } else {
          this.num = res
        }
      })
    },
    // 是否登录
    isLogin () {
      const userId = this.$tools.localRead('userId')
      if (userId) {
        return true
      } else {
        return false
      }
    },
    /**
     * @description 跳转我的购物车
     * @author 穆宏宇
     * @date 2020-09-03 11:21:45
     * @param
     * @return
     * */
    settleup () {
      if (this.isLogin()){
        this.$router.push('my-cart')
      }else {
        this.$router.push('login')
      }
    },
    // 客户支持
    customerService () {
      this.$router.push('/service-support?pageType=5')
    }
  }
}
</script>

<style scoped lang='scss'>
.common-cursor {
  position: fixed;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: #909399;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  width: 60px;
  z-index: 2001;
  cursor: pointer;
  a {
    color: #909399;
  }
  &-item {
    justify-content: center;
    height: 60px;
    text-align: center;
    border-bottom: 1px solid #eee;
    i {
      font-size: 28px;
      padding: 6px 6px 0;
    }
    &:last-child {
      border-bottom: none;
    }
    &.active,
    &:hover {
      color: $--color-primary;
    }
  }
}
</style>
